package com.example.administrator.yuejian_2.activity;

import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import android.widget.RadioGroup;

import com.example.administrator.yuejian_2.R;
import com.example.administrator.yuejian_2.fragment.ActivityOrderListFragment;
import com.example.administrator.yuejian_2.fragment.TrainOrderListFragment;

public class OrderListActivity extends AppCompatActivity {
    private RadioGroup radioGroup_order;
    private int user_id;
    private Context context;
    private ImageButton back;

    private TrainOrderListFragment trainOrderListFragment;
    private ActivityOrderListFragment activityOrderListFragment;

    private FragmentManager fragmentManager;
    private FragmentTransaction fragmentTransaction;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        fragmentManager = getSupportFragmentManager();
        setContentView(R.layout.activity_order_list);
        back = (ImageButton) findViewById(R.id.back);
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        radio();
    }
    public void radio(){
        radioGroup_order = (RadioGroup) findViewById(R.id.radioGroup_order);
        radioGroup_order.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId){
                    case R.id.train:
                        trainOrderListFragment = new TrainOrderListFragment();
                        replaceFragment(trainOrderListFragment);
                        break;
                    case R.id.activity:
                        activityOrderListFragment = new ActivityOrderListFragment();
                        replaceFragment(activityOrderListFragment);
                        break;
                }
            }
        });
        radioGroup_order.check(R.id.train);

    }
    private void replaceFragment(Fragment fragment){
        fragmentManager= getSupportFragmentManager();
        fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.replace(R.id.fragment_holder_order,fragment);
        fragmentTransaction.commit();
    }

}
